<template>
	<pager ref="pager" @loadData="loadData" auth bottombar background-color="#ffffff">

		<view class="safe-bottom flex flex-col w100">
			<view class="box1 flex flex-col w100">
				<view class="title">HBLD2超轻款 序列号：DL2333</view>
				<view class="form-content">
					<u-form>
						<u-form-item :border-bottom="false">
							<u-input :customStyle="{
							height: '160rpx',
							padding: '0rpx',
							fontSize: '26rpx',
						}" :autoHeight="false" maxlength="500" :border="false" type="textarea" v-model="remark"
								placeholder="请具体描述你的问题，并补充设备名称等必要信息"></u-input>
						</u-form-item>
						<u-form-item :border-bottom="false">
							<u-upload :file-list="fileList" width="98" height="98" :max-count="9" :auto-upload="true"
								:limitType="['png', 'jpg', 'jpeg', 'image']" :size-type="['compressed']"
								:action="$api.getUploadImageUrl()" :show-progress="true" :maxSize="5242880"
								:header="$api.getPublicHeader()" ref="upload" :custom-btn="true">
								<view slot="addBtn" class="slot-btn flex flex-row align-c justify-b">
									<view class="add-btn flex-shrink">
										<u-icon name="plus-circle-fill" size="40" color="#999999"></u-icon>
									</view>
									<view class="infos flex flex-shrink flex-col align-s justify-s">
										<view class="txt1">添加图片或视频</view>
										<view class="txt2">建议视频不超过1分钟</view>
									</view>
								</view>
							</u-upload>
						</u-form-item>
					</u-form>
				</view>
				<view class="form-contact">
					<u-input :customStyle="{
						padding: '0rpx',
						fontSize: '26rpx',
					}" :autoHeight="false" maxlength="11" :border="false" type="text" v-model="phone"
						placeholder="为快速解决问题，请留下您的手机号码"></u-input>
				</view>
			</view>
		</view>

		<template v-slot:bottombar>

			<view class="bottombar solid-top">
				<view class="bottombar-content">
					<view hover-class="click-view" @click="submit" class="submit flex align-c justify-c">
						提交
					</view>
				</view>
			</view>
		</template>
	</pager>
</template>

<script>
	export default {
		data() {
			return {
				remark: null,
				fileList: [],
				phone: null,
			}
		},
		methods: {
			loadData() {
				const vm = this
				vm.$refs.pager.finish()
				vm.remark = ' '
				vm.$nextTick(function() {
					// #ifdef MP-WEIXIN
					vm.remark = null
					// #endif
					// #ifdef MP-ALIPAY
					vm.remark = ''
					// #endif
				})
			},
			submit() {
				const vm = this

				if (vm.$utils.isEmpty(vm.formData.expressId)) {
					vm.$utils.showToast('请填写寄回快递单号')
					return
				} else if (vm.$utils.isEmpty(vm.formData.expressId)) {
					vm.$utils.showToast('请填写快递公司名称')
					return
				}

				let files = vm.$refs.upload.lists
				let images = []
				if (files && files.length > 0) {
					let isUploadSuccess = vm.$XEUtils.every(files, item => (item.progress == 100 && !item.error && item
						.response && item.response.data && item.response.data.imgUrl))
					if (!isUploadSuccess) {
						vm.$utils.showToast('有图片上传失败或正在上传')
						return
					} else {
						images = files.map(item => {
							return item.response.data.imgUrl
						})
					}
				}
				console.log(images)

				if (vm.type == 'return') {
					let params = {
						bigOrderId: vm.bigOrderId,
						subOrderIds: vm.subOrderIds,
						expressId: vm.formData.expressId,
						expressName: vm.formData.expressName,
						remark: vm.formData.remark
					}
					if (images && images.length > 0) {
						params['images'] = images
					}
					vm.$api
						.returnSubmitExpressInfo(params)
						.then(res => {
							uni.$emit('refresh-order-list')
							uni.$emit('refresh-order-detail')
							uni.showModal({
								showCancel: false,
								content: '提交物流单号信息成功',
								success() {
									uni.navigateBack({
										delta: 3
									})
								}
							})
						})
						.catch(error => {
							vm.$utils.showToast(error)
						})
				} else if (vm.type == 'service') {
					let params = {
						id: vm.serviceId,
						expressId: vm.formData.expressId,
						expressName: vm.formData.expressName,
						remark: vm.formData.remark
					}
					if (images && images.length > 0) {
						params['images'] = images
					}
					vm.$api
						.serviceSubmitExpressInfo(params)
						.then(res => {
							uni.$emit('refresh-order-list')
							uni.$emit('refresh-order-detail')
							uni.$emit('refresh-afterSale')
							uni.showModal({
								showCancel: false,
								content: '提交物流单号信息成功',
								success() {
									uni.navigateBack({
										delta: 1
									})
								}
							})
						})
						.catch(error => {
							vm.$utils.showToast(error)
						})
				}
			}
		}
	}
</script>
<style>
	page {
		background-color: #ffffff;
	}
</style>
<style scoped lang="scss">
	.bottombar {
		background-color: #FFFFFF;

		.bottombar-content {
			padding: 30rpx;

			.submit {
				font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;
				height: 94rpx;
				background: linear-gradient(180deg, #427DF7 0%, #0B51E4 100%);
				border-radius: 48rpx;
			}
		}
	}

	.box1 {
		padding: 30rpx;

		.title {
			font-size: 26rpx;
			color: #353535;
		}

		.form-content {
			margin-top: 20rpx;
			padding: 30rpx;
			padding-bottom: 20rpx;
			background-color: #F8F8F8;
			margin-bottom: 20rpx;
			border-radius: 8rpx;

			/deep/ .u-form-item {
				padding: 0rpx;
			}

			/deep/ .u-list-item {
				background: #EBEBEB;
			}

			/deep/ .u-upload {
				margin: 0 -10rpx;
			}

			.slot-btn {
				margin: 10rpx;

				.add-btn {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 98rpx;
					height: 98rpx;
					background: #EBEBEB;
					border-radius: 16rpx;
				}

				.infos {
					margin: 0 16rpx;

					.txt1 {
						font-size: 26rpx;
						font-weight: bold;
						color: #353535;
						line-height: 36rpx;
					}

					.txt2 {
						margin-top: 10rpx;
						font-size: 22rpx;
						color: #878787;
						line-height: 32rpx;
					}
				}
			}
		}

		.form-contact {
			padding: 10rpx 30rpx;
			background-color: #F8F8F8;
			margin-bottom: 20rpx;
			border-radius: 8rpx;
		}

	}
</style>